import requests

# api_root = "https://192.168.122.66:8000/api"
api_root = "http://localhost:8000/api"


def login(username, password):
    return requests.post(api_root + "/login", json={
        "login": username,
        "password": password
    }, verify=False)


def send_request(_topic: str, _description: str, access_token: str):
    if _description is None:
        _description = ""
    return requests.post(api_root + "/req/create", json={
        "topic": _topic,
        "description": _description
    }, headers={
        "Authorization": "Bearer " + access_token
    }, verify=False)


def get_last_user_request(access_token: str, page: int, status: str = None):
    # id - это номер с конца
    url = api_root + "/req_full/all?page={}&size=1".format(page)
    if status is not None:
        url += "&status={}".format(status)
    return requests.get(url, headers={
        "Authorization": "Bearer " + access_token
    }, verify=False)


def get_response(access_token: str, req_id: int):
    # id - это номер с конца
    url = api_root + "/resp/{}".format(req_id)
    return requests.get(url, headers={
        "Authorization": "Bearer " + access_token
    }, verify=False)
